<?php
/**
 * 类说明 :
 * User: 刘明昆
 * Date: 2019-1-28
 * Time: 16:06
 */
header("Content-type: text/html; charset=utf-8");
require 'dbUtils.php';
require 'jsonMsg.php';

//获取数据库实例
$link=mysqlDB::getInstance();

$page=$_POST['page'];
$rows=$_POST['rows'];

if(!isset($_POST['title'])){
    $pages=($page-1)*10;
//分页查询
    $sql=" SELECT * FROM admin limit $pages,$rows;";

//查询总记录数
    $sql2="select count(*) as sum from admin;";
//执行sql
    $result=$link->query($sql);
//执行
    $result2=$link->query($sql2);
    $res = mysqli_fetch_array($result2);

    $count = $res['sum'];
    $arr=array();
    if(mysqli_num_rows($result)<1){
        return jsonlist(0,$arr);
    }else{
        while($row=mysqli_fetch_assoc($result)){
            $arr[]=$row;
        }
        return jsonlist($arr,$count);
    }
}else{
    $title=$_POST['title'];
    $pages=($page-1)*10;
//分页查询
    $sql=" SELECT * FROM admin  where title like '%$title%' limit $pages,$rows;";
//查询总记录数
    $sql2="select count(*) as sum from admin  where title like '%$title%';";
//执行sql
    $result=$link->query($sql);
//执行
    $result2=$link->query($sql2);
    $res = mysqli_fetch_array($result2);

    $count = $res['sum'];
    $arr=array();
    if(mysqli_num_rows($result)<1){
        return jsonlist(0,$arr);
    }else{
        while($row=mysqli_fetch_assoc($result)){
            $arr[]=$row;
        }
        return jsonlist($arr,$count);
    }

}


